import request from '@/utils/request'
import { LOGIN_TOKEN } from '../actionsType'
import { setToken } from '../../utils/storage'

export function login ({ mobile, code }) {
  async function fn (dispatch) {
    const res = await request({
      method: 'post',
      url: 'authorizations',
      data: {
        mobile,
        code
      }
    })
    const token = res.data.token
    setToken(token)
    dispatch({ type: LOGIN_TOKEN, payload: res.data.token })
  }
  return fn
}
